package com.cctc.security.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ColumnResult;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;

import com.cctc.framework.bean.BaseObj;
import com.cctc.security.util.SqlUtil;

@Entity
@Table(name = "CCTCT_RESOURCES")
@NamedNativeQueries({ 
    @NamedNativeQuery(name = SqlUtil.NAME_GET_RESOURCE_URL_BY_AUTHORITE_NAME, query = SqlUtil.SQL_GET_RESOURCE_URL_BY_AUTHORITE_NAME, resultSetMapping = SqlUtil.RSM_GET_RESOURCE_URL_BY_AUTHORITE_NAME)
})
@SqlResultSetMappings(value = { 
@SqlResultSetMapping(name=SqlUtil.RSM_GET_RESOURCE_URL_BY_AUTHORITE_NAME,columns={@ColumnResult(name="URL")})
})
public class Resource extends BaseObj
{
    
    private static final long serialVersionUID = -9162593029478001824L;
    
    @Id
    @Column(length = 100, nullable = false)
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = SqlUtil.HIBERNATE_UUID)
    private String id;
    
    @Column(name = "NAME", length = 30, unique = true, nullable = false)
    private String name;
    
    @Column(name = "TYPE", length = 10, nullable = false)
    private String type;
    
    @Column(name = "PRIORITY", nullable = false)
    private int priority;
    
    @Column(name = "URL", nullable = false, length = 200, unique = true)
    private String url;
    
    @Column(name = "ENABLED", nullable = false)
    private int enabled;
    
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "CCTCT_RESOURCES_AUTHORITIES", joinColumns = { @JoinColumn(name = "RESOURCE_ID") }, inverseJoinColumns = { @JoinColumn(name = "AUTHORITIE_ID") })
    private List<Authoritie> listAuthorities = new ArrayList<Authoritie>();
    
    public String getId()
    {
        return id;
    }
    
    public void setId(String id)
    {
        this.id = id;
    }
    
    public String getName()
    {
        return name;
    }
    
    public void setName(String name)
    {
        this.name = name;
    }
    
    public String getType()
    {
        return type;
    }
    
    public void setType(String type)
    {
        this.type = type;
    }
    
    public int getPriority()
    {
        return priority;
    }
    
    public void setPriority(int priority)
    {
        this.priority = priority;
    }
    
    public String getUrl()
    {
        return url;
    }
    
    public void setUrl(String url)
    {
        this.url = url;
    }
    
    public int getEnabled()
    {
        return enabled;
    }
    
    public void setEnabled(int enabled)
    {
        this.enabled = enabled;
    }
    
    public List<Authoritie> getListAuthorities()
    {
        return listAuthorities;
    }
    
    public void setListAuthorities(List<Authoritie> listAuthorities)
    {
        this.listAuthorities = listAuthorities;
    }
    
}
